/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmlparser;

/**
 *
 * @author pbelov
 */
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.*;
import java.util.Vector;

public class deviceParser extends DefaultHandler{

    String device[];
    Vector vd = new Vector();

    String thisElement = "";

    public static String DEVICE = "device";

    public String[] getResult(){
        return device;
    }

    public void fill(String[] devices) {
        for (int i = 0; i < devices.length; i++) {
            devices[i] = (String)vd.elementAt(i);
        }
    }

    public int getCount() {
        return vd.size();
    }

    @Override
    public void startDocument() throws SAXException {
      System.out.println("Start parse device XML...");
    }

    @Override
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
        thisElement = qName;
    }

    @Override
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
        thisElement = "";
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        if (thisElement.equals(DEVICE)) {
            vd.add(new String(ch, start, length));
        }
    }

    @Override
    public void endDocument() {
        System.out.println("Stop parse device XML...");
    }
}


